package edu.fudan.jwxt.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import edu.fudan.jwxt.Exception.ServiceException;
import edu.fudan.jwxt.common.Constants;
import edu.fudan.jwxt.dao.StudentCourseVODao;
import edu.fudan.jwxt.entity.VO.StudentCourseVO;
import edu.fudan.jwxt.service.StudentCourseVOService;
import org.springframework.stereotype.Service;

@Service
public class StudentCourseVOServiceImpl extends ServiceImpl<StudentCourseVODao, StudentCourseVO> implements StudentCourseVOService {

    @Override
    public boolean save(StudentCourseVO entity) {
        LambdaQueryWrapper<StudentCourseVO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StudentCourseVO::getUid,entity.getUid())
                //.eq(StudentCourseVO::getClassId,entity.getClassId())
                .eq(StudentCourseVO::getCourseId,entity.getCourseId());
        StudentCourseVO one = getOne(queryWrapper);

        if(one != null)
            throw new ServiceException(Constants.CODE_600,"您已存在于该课程中");
        return super.save(entity);
    }
}
